﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Configuration;
using System.Threading;
using System.IO;
using System.Collections.Generic;
using System.Net;
using XmlServer.ServiceContracts;
using XmlServer.ServiceImplementation;

namespace UnitTests
{
    [TestClass]
    public class XMLServerTests
    {

        // variables populates in the [ClassInitialize]
        private string ipAddress;
        private int processorPort;
        private int priorityPort;
        private int priorityThreads;
        private int processorThreads;
        private string operatorsFolder;


        
        
        // This is the IP Address and Port for the Windows Service Test;  That is, this is the location where the windows service is installed.
        //  Don't forget to open the port in the Firewall on the server
        private string windowsServiceIpAddress = "192.168.0.9";
        private int windowsServiceProcessorPort = 8095;


        // server created in the [TestInitialize]
        private XmlServer.Server server;

        private XmlServer.Server CreateServer(string ipAddress, int processorPort, int priorityPort, int processorThreads, int priorityThreads, string operatorFolder)
        {
            // create the server class
            var _server = new XmlServer.Server();

            _server.ProcessingListener.Configuration.IPAddress = ipAddress;
            _server.ProcessingListener.Configuration.Port = processorPort;
            _server.ProcessingListener.Configuration.OperatorsFolder = operatorFolder;
            _server.ProcessingListener.Configuration.NumberOfThreads = processorThreads;

            _server.PriorityListener.Configuration.IPAddress = ipAddress;
            _server.PriorityListener.Configuration.Port = priorityPort;
            _server.PriorityListener.Configuration.OperatorsFolder = operatorFolder;
            _server.PriorityListener.Configuration.NumberOfThreads = priorityThreads;

            // create the events for processing listener
            _server.ProcessingListener.ListenerDebugMessage += Listener_ListenerDebugMessage;
            _server.ProcessingListener.ListenerException += Listener_ListenerException;
            _server.ProcessingListener.ListenerPaused += Listener_ListenerPaused;
            _server.ProcessingListener.ListenerRequestCompleted += Listener_ListenerRequestCompleted;
            _server.ProcessingListener.ListenerRequestServicing += Listener_ListenerRequestServicing;
            _server.ProcessingListener.ListenerRequestStarted += Listener_ListenerRequestStarted;
            _server.ProcessingListener.ListenerResumed += Listener_ListenerResumed;
            _server.ProcessingListener.ListenerStarted += Listener_ListenerStarted;
            _server.ProcessingListener.ListenerStopped += Listener_ListenerStopped;

            // create the sam events for the priority listener
            _server.PriorityListener.ListenerDebugMessage += Listener_ListenerDebugMessage;
            _server.PriorityListener.ListenerException += Listener_ListenerException;
            _server.PriorityListener.ListenerPaused += Listener_ListenerPaused;
            _server.PriorityListener.ListenerRequestCompleted += Listener_ListenerRequestCompleted;
            _server.PriorityListener.ListenerRequestServicing += Listener_ListenerRequestServicing;
            _server.PriorityListener.ListenerRequestStarted += Listener_ListenerRequestStarted;
            _server.PriorityListener.ListenerResumed += Listener_ListenerResumed;
            _server.PriorityListener.ListenerStarted += Listener_ListenerStarted;
            _server.PriorityListener.ListenerStopped += Listener_ListenerStopped;

            return _server;
        }


        [TestInitialize]
        public void InitializeServer()
        {
            // load the required variables from app.config
            ipAddress = GetAppSetting<string>("ProcessListener_IPAddress");
            if (String.IsNullOrEmpty(ipAddress)) ipAddress = XmlServer.Helper.Utilities.GetLocalIpAddress();

            processorPort = GetAppSetting<int>("ProcessListener_Port");
            priorityPort = GetAppSetting<int>("PriorityListener_Port");

            priorityThreads = GetAppSetting<int>("PriorityListener_NumThreads");
            processorThreads = GetAppSetting<int>("ProcessListener_NumThreads");
            operatorsFolder = Path.Combine(System.Environment.CurrentDirectory, GetAppSetting<string>("OperatorsFolder"));

            this.server = CreateServer(ipAddress, processorPort, priorityPort, processorThreads, priorityThreads, operatorsFolder);
        }


        #region Server Tests : Local Server Tests

        [Owner("Server Only Test"), TestMethod]
        public void StartStopServer()
        {
            try
            {
                // make sure we have a server
                Assert.IsNotNull(server);
                Assert.IsFalse(server.Listening);  // the server has not started

                // start the server
                server.StartListening();
                Assert.IsTrue(server.Listening);

                // sleep the test thread and let the server run for a few seconds.
                Thread.Sleep(3000);
            }
            finally
            {
                // shut down server
                server.Shutdown();
                Assert.IsFalse(server.Listening);
            }


        }


        [Owner("Server Test"), TestMethod]
        public void StartPauseResumeStopServer()
        {
            try
            {
                // make sure we have a server
                Assert.IsNotNull(server);
                Assert.IsFalse(server.Listening);  // the server has not started

                // start the server
                server.StartListening();
                Assert.IsTrue(server.Listening);

                // sleep the test thread and let the server run for a few seconds.
                Thread.Sleep(3000);

                // Pause the server
                server.PauseListening();
                Assert.IsTrue(server.Paused);

                // Resume the server
                server.ResumeListening();
                Assert.IsFalse(server.Paused);
            }
            finally
            {
                // shut down server
                server.Shutdown();
                Assert.IsFalse(server.Listening);
            }


        }


        #endregion

        #region Operator Tests : Client and Server

        [Owner("Server and Client Test"), TestMethod]
        public void GetStatusTest()
        {

            try
            {
                // start the server
                server.StartListening();

                // get the request string
                string request = XmlServer.Helper.Utilities.CreateRequest("Status", "1.0", null);

                // send the request and get the response
                var response1 = XmlServer.Helper.Utilities.MakeRequest(request, ipAddress, processorPort);
                var successResponse1 = XmlServer.Helper.Utilities.IsResponseSuccess(response1);
                Assert.IsTrue(successResponse1);

                var response2 = XmlServer.Helper.Utilities.MakeRequest(request, ipAddress, priorityPort);
                var successResponse2 = XmlServer.Helper.Utilities.IsResponseSuccess(response2);
                Assert.IsTrue(successResponse2);

                Assert.IsNotNull(response1);
                Assert.IsNotNull(response2);

            }
            finally
            {
                // shut down server
                server.Shutdown();
                Assert.IsFalse(server.Listening);
            }



        }

        [Owner("Server and Client Test"), TestMethod]
        public void EchoOperatorTest()
        {

            try
            {
                // start the server
                server.StartListening();

                // create 3 guids that should be echoed back
                var guid1 = Guid.NewGuid().ToString();
                var guid2 = Guid.NewGuid().ToString();
                var guid3 = Guid.NewGuid().ToString();


                // get the request string
                string request = XmlServer.Helper.Utilities.CreateRequest("Echo Operator", "1.0",
                    new List<IFact>
                {
                    new Fact { Name = "GuidValue1", Value = guid1 },
                    new Fact { Name = "GuidValue2", Value = guid2 },
                    new Fact { Name = "GuidValue3", Value = guid3 }
                });


                // send the request and XmlServer.Helper the response
                var response = XmlServer.Helper.Utilities.MakeRequest(request, ipAddress, processorPort);

                // parse the response
                var data = XmlServer.Helper.Utilities.GetFacts(response, true);
                var successResponse = XmlServer.Helper.Utilities.IsResponseSuccess(response);

                Assert.IsNotNull(data);             // we should get data back from the server
                Assert.IsTrue(successResponse);     // the response should return true
                Assert.IsTrue(data.Count == 3);     // we should get 3 records back from the server

                // check that we successfully echo'd the values back
                Assert.IsTrue(XmlServer.Helper.Utilities.ContainsFact(data, "GuidValue1"));
                Assert.IsTrue(XmlServer.Helper.Utilities.GetFact(data, "GuidValue1").Equals(guid1));

                Assert.IsTrue(XmlServer.Helper.Utilities.ContainsFact(data, "GuidValue2"));
                Assert.IsTrue(XmlServer.Helper.Utilities.GetFact(data, "GuidValue2").Equals(guid2));

                Assert.IsTrue(XmlServer.Helper.Utilities.ContainsFact(data, "GuidValue3"));
                Assert.IsTrue(XmlServer.Helper.Utilities.GetFact(data, "GuidValue3").Equals(guid3));

            }
            finally
            {
                // shut down server
                server.Shutdown();
                Assert.IsFalse(server.Listening);
            }

        }

        [Owner("Server and Client Test"), TestMethod]
        public void EchoOperatorTest_VeryLarge()
        {

            try
            {
                // start the server
                server.StartListening();

                // create a large echo text string....over 8129 characters
                int stringSize = 100123;
                var LargeText = new string('*', stringSize);



                // get the request string
                string request = XmlServer.Helper.Utilities.CreateRequest("Echo Operator", "1.0",
                    new List<IFact>
                {
                    new Fact { Name = "LargeText", Value = LargeText }
                });


                // send the request and get the response
                var response = XmlServer.Helper.Utilities.MakeRequest(request, ipAddress, processorPort);

                // parse the response
                var data = XmlServer.Helper.Utilities.GetFacts(response, true);
                var successResponse = XmlServer.Helper.Utilities.IsResponseSuccess(response);

                Assert.IsNotNull(data);             // we should get data back from the server
                Assert.IsTrue(successResponse);     // the response should return true

                // check that we successfully echo'd the values back
                Assert.IsTrue(XmlServer.Helper.Utilities.ContainsFact(data, "LargeText"));

                var responseLargeText = XmlServer.Helper.Utilities.GetFact(data, "LargeText");
                Assert.IsTrue(responseLargeText.Length == stringSize);
                Assert.IsTrue(responseLargeText == LargeText);
            }
            finally
            {
                // shut down server
                server.Shutdown();
                Assert.IsFalse(server.Listening);
            }

        }

        [Owner("Server and Client Test"), TestMethod]
        public void DelayOperatorTest()
        {

            try
            {
                // start the server
                server.StartListening();

                // get the request string
                string request = XmlServer.Helper.Utilities.CreateRequest("Delay Operator", "1.0",
                    new List<IFact>
                {
                    new Fact { Name =  "Delay", Value = "10"},
                    new Fact { Name = "delayType", Value = "secs"}                    
                });


                // send the request and get the response
                var response = XmlServer.Helper.Utilities.MakeRequest(request, ipAddress, processorPort);

                // parse the response
                var data = XmlServer.Helper.Utilities.GetFacts(response, true);
                var successResponse = XmlServer.Helper.Utilities.IsResponseSuccess(response);

                Assert.IsNotNull(data);             // we should get data back from the server
                Assert.IsTrue(successResponse);     // the response should return true
            }
            finally
            {
                // shut down server
                server.Shutdown();
                Assert.IsFalse(server.Listening);
            }
        }

        [Owner("Server and Client Test"), TestMethod]
        public void ExceptionOperatorTest_Graceful()
        {
            try
            {
                // start the server
                server.StartListening();

                // get the request string

                // "gracefully" cause an exception in the operator
                string request = XmlServer.Helper.Utilities.CreateRequest("Exception Operator", "1.0",
                    new List<IFact>
                {
                    new Fact{ Name="ThrowException", Value="false"}
                });


                // send the request and get the response
                var response = XmlServer.Helper.Utilities.MakeRequest(request, ipAddress, processorPort);

                // parse the response
                var data = XmlServer.Helper.Utilities.GetFacts(response, true);
                var successResponse = XmlServer.Helper.Utilities.IsResponseSuccess(response);

                Assert.IsNotNull(data);             // we should get data back from the server
                Assert.IsFalse(successResponse);     // the response should return true
            }
            finally
            {
                // shut down server
                server.Shutdown();
                Assert.IsFalse(server.Listening);
            }

        }

        [Owner("Server and Client Test"), TestMethod]
        public void ExceptionOperatorTest_Exception()
        {
            try
            {
                // start the server
                server.StartListening();

                // get the request string

                // "gracefully" cause an exception in the operator
                string request = XmlServer.Helper.Utilities.CreateRequest("Exception Operator", "1.0",
                    new List<IFact>
                {
                    new Fact{ Name="ThrowException", Value="true"}
                });


                // send the request and get the response
                var response = XmlServer.Helper.Utilities.MakeRequest(request, ipAddress, processorPort);

                // parse the response
                var data = XmlServer.Helper.Utilities.GetFacts(response, true);
                var successResponse = XmlServer.Helper.Utilities.IsResponseSuccess(response);

                Assert.IsNotNull(data);             // we should get data back from the server
                Assert.IsFalse(successResponse);     // the response should return true
            }
            finally
            {
                // shut down server
                server.Shutdown();
                Assert.IsFalse(server.Listening);
            }

        }

        [Owner("Server and Client Test"), TestMethod]
        public void MathOperatorTest()
        {

            try
            {
                // start the server
                server.StartListening();

                // get the request string
                string request = XmlServer.Helper.Utilities.CreateRequest("Math Operator", "1.0",
                    new List<IFact>
                {
                    new Fact { Name = "FirstNumber", Value = "10"},
                    new Fact { Name = "SecondNumber", Value = "20"},
                    new Fact { Name = "Operation", Value = "add"}
                });


                // send the request and get the response
                var response = XmlServer.Helper.Utilities.MakeRequest(request, ipAddress, processorPort);

                // parse the response
                var data = XmlServer.Helper.Utilities.GetFacts(response, true);
                var successResponse = XmlServer.Helper.Utilities.IsResponseSuccess(response);

                Assert.IsNotNull(data);             // we should get data back from the server
                Assert.IsTrue(successResponse);     // the response should return true
            }
            finally
            {
                // shut down server
                server.Shutdown();
                Assert.IsFalse(server.Listening);
            }

        }

        [Owner("Server and Client Test"), TestMethod]
        public void TimeOperatorTest()
        {
            try
            {
                // start the server
                server.StartListening();

                // get the request string
                string request = XmlServer.Helper.Utilities.CreateRequest("Time Operator", "1.0", null);


                // send the request and get the response
                var response = XmlServer.Helper.Utilities.MakeRequest(request, ipAddress, processorPort);

                // parse the response
                var data = XmlServer.Helper.Utilities.GetFacts(response, true);
                var successResponse = XmlServer.Helper.Utilities.IsResponseSuccess(response);

                Assert.IsNotNull(data);             // we should get data back from the server
                Assert.IsTrue(successResponse);     // the response should return true
            }
            finally
            {
                // shut down server
                server.Shutdown();
                Assert.IsFalse(server.Listening);
            }

        }

        [Owner("Server and Client Test"), TestMethod]
        public void QuickReturnOperatorTest()
        {
            try
            {
                // start the server
                server.StartListening();

                // get the request string
                string request = XmlServer.Helper.Utilities.CreateRequest("Quick Return Operator", "1.0", null);


                // send the request and get the response
                var response = XmlServer.Helper.Utilities.MakeRequest(request, ipAddress, processorPort);

                // parse the response
                var data = XmlServer.Helper.Utilities.GetFacts(response, true);
                var successResponse = XmlServer.Helper.Utilities.IsResponseSuccess(response);

                Assert.IsNotNull(data);             // we should get data back from the server
                Assert.IsTrue(successResponse);     // the response should return true
            }
            finally
            {
                // shut down server
                server.Shutdown();
                Assert.IsFalse(server.Listening);
            }
        }

        [Owner("Server and Client Test"), TestMethod]
        public void LogEventOperatorTest()
        {
            try
            {
                // start the server
                server.StartListening();

                // get the request string
                string request = XmlServer.Helper.Utilities.CreateRequest("LogEvent Operator", "1.0",
                    new List<IFact>
                {
                    new Fact { Name = "Source", Value = "XMLServer"},
                    new Fact { Name = "Log", Value = "Application"},
                    new Fact { Name = "Message", Value = "Hello from the XML Server applicaion"},
                    new Fact { Name = "EventType", Value = "Information"}
                });


                // send the request and get the response
                var response = XmlServer.Helper.Utilities.MakeRequest(request, ipAddress, processorPort);

                // parse the response
                var data = XmlServer.Helper.Utilities.GetFacts(response, true);
                var successResponse = XmlServer.Helper.Utilities.IsResponseSuccess(response);

                Assert.IsNotNull(data);             // we should get data back from the server
                Assert.IsTrue(successResponse);     // the response should return true

            }
            finally
            {
                // shut down server
                server.Shutdown();
                Assert.IsFalse(server.Listening);
            }
        }

        [Owner("Server and Client Test"), TestMethod]
        public void DBQueryOperatorTest()
        {
            try
            {
                // start the server
                server.StartListening();

                // get the request string
                string request = XmlServer.Helper.Utilities.CreateRequest("DBQuery Operator", "1.0", null);

                // send the request and get the response
                var response = XmlServer.Helper.Utilities.MakeRequest(request, ipAddress, processorPort);

                // parse the response
                var data = XmlServer.Helper.Utilities.GetFacts(response, true);
                var successResponse = XmlServer.Helper.Utilities.IsResponseSuccess(response);

                Assert.IsNotNull(data);             // we should get data back from the server
                // Not implemented yet!
                // Assert.IsTrue(successResponse);
            }
            finally
            {
                // shut down server
                server.Shutdown();
                Assert.IsFalse(server.Listening);
            }
        }

        [Owner("Server and Client Test"), TestMethod]
        public void Relay_TimeOperatorTest()
        {

            // Make a call the the TimeServer, however, request that the first XmlServer relays the information
            // to a second XmlServer...maybe useful for making a load balancer in the future along with the status server 1.0 requests

            // create the relay server.
            //  the xml will be sent to this server and relayed to another server
            var relayServer = CreateServer(ipAddress, processorPort + 10, priorityPort + 11, 2, 1, operatorsFolder);

            try
            {
                relayServer.StartListening();

                // start the server
                server.StartListening();


                // create the request for the time server with the relay parameters
                // the request will be forwarded to the relay server
                string request = XmlServer.Helper.Utilities.CreateRequest("Time Operator", "1.0", null, ipAddress, processorPort + 10);


                // send the request and get the response            
                var response = XmlServer.Helper.Utilities.MakeRequest(request, ipAddress, processorPort);

                // parse the response
                var data = XmlServer.Helper.Utilities.GetFacts(response, true);
                var successResponse = XmlServer.Helper.Utilities.IsResponseSuccess(response);

                Assert.IsNotNull(data);             // we should get data back from the server
                Assert.IsTrue(successResponse);     // the response should return true

            }
            finally
            {
                // shut down servers
                server.Shutdown();
                relayServer.Shutdown();
            }

        }

        #endregion

        #region Client Tests : Testing Client application calling the Windows Servic e

        [Owner("Client Only Tests"), TestMethod]
        public void TimeOperator_ClientOnly_Test()
        {
            try
            {
                // get the request string
                string request = XmlServer.Helper.Utilities.CreateRequest("Time Operator", "1.0", null);

                System.Diagnostics.Debug.WriteLine("Request:");
                System.Diagnostics.Debug.WriteLine(request);
                System.Diagnostics.Debug.WriteLine("");

                // Enter in the ipAddress of your window service installation
                ipAddress = windowsServiceIpAddress;
                processorPort = windowsServiceProcessorPort;

                // send the request and get the response
                var response = XmlServer.Helper.Utilities.MakeRequest(request, ipAddress, processorPort);
                System.Diagnostics.Debug.WriteLine("response:");
                System.Diagnostics.Debug.WriteLine(response);
                System.Diagnostics.Debug.WriteLine("");

                // parse the response
                var successResponse = XmlServer.Helper.Utilities.IsResponseSuccess(response);
                System.Diagnostics.Debug.WriteLine(String.Format("successResponse = {0}", successResponse));
                System.Diagnostics.Debug.WriteLine("");

                var facts = XmlServer.Helper.Utilities.GetFacts(response, true);
                System.Diagnostics.Debug.WriteLine("response:");
                foreach (var fact in facts)
                {
                    System.Diagnostics.Debug.WriteLine(String.Format("{0} = {1}", fact.Name, fact.Value));
                }


                Assert.IsTrue(successResponse);     // the response should return true
                Assert.IsNotNull(facts);             // we should get data back from the server
                
            }
            catch (Exception err)
            {
                System.Diagnostics.Debug.WriteLine(err.ToString());
                Assert.Fail();
            }
        }


        [Owner("Client Only Tests"), TestMethod]
        public void EchoOperator_ClientOnly_Test()
        {
            try
            {
                // create a large echo text string....over 8129 characters
                /*
                int stringSize = 100123;
                var LargeText = new string('*', stringSize);
                */
                var LargeText = "Hello XmlServer, this is Ann....Are you there";

                // get the request string
                string request = XmlServer.Helper.Utilities.CreateRequest("Echo Operator", "1.0",
                    new List<IFact>
                    {
                        new Fact { Name = "LargeText", Value = LargeText }
                    });


                System.Diagnostics.Debug.WriteLine("Request:");
                System.Diagnostics.Debug.WriteLine(request);
                System.Diagnostics.Debug.WriteLine("");

                // Enter in the ipAddress of your window service installation
                ipAddress = windowsServiceIpAddress;
                processorPort = windowsServiceProcessorPort;

                // send the request and get the response
                var response = XmlServer.Helper.Utilities.MakeRequest(request, ipAddress, processorPort);
                System.Diagnostics.Debug.WriteLine("response:");
                System.Diagnostics.Debug.WriteLine(response);
                System.Diagnostics.Debug.WriteLine("");

                // parse the response
                var successResponse = XmlServer.Helper.Utilities.IsResponseSuccess(response);
                System.Diagnostics.Debug.WriteLine(String.Format("successResponse = {0}", successResponse));
                System.Diagnostics.Debug.WriteLine("");

                var facts = XmlServer.Helper.Utilities.GetFacts(response, true);
                System.Diagnostics.Debug.WriteLine("response:");
                foreach (var fact in facts)
                {
                    System.Diagnostics.Debug.WriteLine(String.Format("{0} = {1}", fact.Name, fact.Value));
                }


                Assert.IsTrue(successResponse);     // the response should return true
                Assert.IsNotNull(facts);             // we should get data back from the server

            }
            catch (Exception err)
            {
                System.Diagnostics.Debug.WriteLine(err.ToString());
                Assert.Fail();
            }
        }

        #endregion

        #region Private Methods



        private T GetAppSetting<T>(string Key)
        {
            if (String.IsNullOrEmpty(Key)) return default(T);

            var value = ConfigurationManager.AppSettings[Key];

            T castedValue = (T)Convert.ChangeType(value, typeof(T));

            return castedValue;

        }

        #endregion

        #region Listener Events

        public void Listener_ListenerDebugMessage(object sender, string IPAddress, int Port, string Message)
        {
            var listener = (XmlServer.Listeners.Listener)sender;
            System.Diagnostics.Debug.WriteLine(String.Format("{0} Listener: {1}", listener.ListenerType, Message));
        }

        public void Listener_ListenerException(object sender, string ClassName, string MethodName, Exception err)
        {
            var listener = (XmlServer.Listeners.Listener)sender;
            System.Diagnostics.Debug.WriteLine(String.Format("{0} Listener ERROR: Classname={1}, MethodName={2}, Error={3}", listener.ListenerType, ClassName, MethodName, err.ToString()));
            
            if (err.InnerException != null)
                Listener_ListenerException(sender, ClassName, MethodName, err.InnerException);
            
        }

        public void Listener_ListenerPaused(object sender, string IPAddress, int Port)
        {
            var listener = (XmlServer.Listeners.Listener)sender;
            System.Diagnostics.Debug.WriteLine(String.Format("{0} Listener: Paused", listener.ListenerType));
        }

        public void Listener_ListenerRequestCompleted(object sender, string ClientIPAddress, int ClientPort, string ReplyData, int Duration)
        {
            var listener = (XmlServer.Listeners.Listener)sender;
            System.Diagnostics.Debug.WriteLine(String.Format("{0} Listener: Request Completed, ReplyData={1}, Duration={2}", listener.ListenerType, ReplyData, Duration));
        }

        public void Listener_ListenerRequestServicing(object sender, string ClientIPAddress, int ClientPort, string RequestData)
        {
            var listener = (XmlServer.Listeners.Listener)sender;
            System.Diagnostics.Debug.WriteLine(String.Format("{0} Listener: Request Servicing, RequestData={1}", listener.ListenerType, RequestData));
        }

        public void Listener_ListenerRequestStarted(object sender, string ClientIPAddress, int ClientPort)
        {
            var listener = (XmlServer.Listeners.Listener)sender;
            System.Diagnostics.Debug.WriteLine(String.Format("{0} Listener: Request Started", listener.ListenerType));
        }

        public void Listener_ListenerResumed(object sender, string IPAddress, int Port)
        {
            var listener = (XmlServer.Listeners.Listener)sender;
            System.Diagnostics.Debug.WriteLine(String.Format("{0} Listener: Resumed", listener.ListenerType));
        }

        public void Listener_ListenerStarted(object sender, string IPAddress, int Port)
        {
            var listener = (XmlServer.Listeners.Listener)sender;
            System.Diagnostics.Debug.WriteLine(String.Format("{0} Listener: Started", listener.ListenerType));
        }

        public void Listener_ListenerStopped(object sender, string IPAddress, int Port)
        {
            var listener = (XmlServer.Listeners.Listener)sender;
            System.Diagnostics.Debug.WriteLine(String.Format("{0} Listener: Stopped", listener.ListenerType));            
        }


        #endregion
    }
}
